package com.sfcms.provider.service;

import com.sfcms.provider.dao.NewsDao;
import com.sfcms.provider.model.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    NewsDao newsDao;

    @Override
    public News save(News news) {
        return newsDao.save(news);
    }

    @Override
    public News update(News news) {
        return newsDao.save(news);
    }

    @Override
    public void delete(Integer id) {
        newsDao.deleteById(id);
    }

    @Override
    public News findNewsById(Integer id) {
        return newsDao.findNewsById(id);
    }

    @Override
    public List<News> findNewsByTitle(String title) {
        return newsDao.findNewsByTitle(title);
    }

    @Override
    public Page<News> findAll(int page, int pageSize) {
        Pageable pageable = PageRequest.of(page, pageSize);
        return newsDao.findAll(pageable);
    }
}